﻿using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using System.Xml.Serialization;

namespace GodotAssetLibrarySpider
{

  

    internal class Program
    {
        static void Main(string[] args)
        {
            UrlFailRecorder.FilePath = Path.Combine(Environment.CurrentDirectory, "fail_record_list.log");
            var allDetailPath = Path.Combine(Environment.CurrentDirectory, "all_detail_list.xml");
            var allDetailList = new List<Detail>();

            for (int i = 1; i <= 40; i++)
            {
                var homePageUrl = ResolveHelper.GetHomePageUrl(i);
                var home = new Home(homePageUrl);
                
                home.Load();
                
                var details = home.Details;

                Console.ForegroundColor = ConsoleColor.Green;

                foreach (var detail in details)
                {
                    Console.WriteLine(detail);
                }

                Thread.Sleep(2000);

                Console.ResetColor();
                foreach (var detail in details)
                {
                    detail.Load();

                    Console.ResetColor();
                    Console.WriteLine(detail);
                    Thread.Sleep(3000);

                    if (string.IsNullOrWhiteSpace(detail.FileURL) == false)
                    {
                        allDetailList.Add(detail);
                        SaveAllDetailList(allDetailList, allDetailPath);
                    }
                }
            }

        }

        static void SaveAllDetailList(List<Detail> allDetailList, string path)
        {
            var xmlSeri = new XmlSerializer(typeof(List<Detail>));
            using var fs = File.Create(path);
            xmlSeri.Serialize(fs, allDetailList);
        }

    }
}
